package com.leadbank.bigdata.mapreduce.mobileflow;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * 自定义数据类型KpiWritable
 * Created by hp on 2018/5/9.
 */
public class KpiWritable implements Writable {

    //上行数据包数，单位：个
    private long upPackNum;
    //下行数据包数，单位：个
    private long downPackNum;
    //上行总流量，单位：byte
    private long upPayLoad;
    //下行总流量，单位：byte
    private long downPayLoad;

    public long getUpPackNum() {
        return upPackNum;
    }

    public void setUpPackNum(long upPackNum) {
        this.upPackNum = upPackNum;
    }

    public long getDownPackNum() {
        return downPackNum;
    }

    public void setDownPackNum(long downPackNum) {
        this.downPackNum = downPackNum;
    }

    public long getUpPayLoad() {
        return upPayLoad;
    }

    public void setUpPayLoad(long upPayLoad) {
        this.upPayLoad = upPayLoad;
    }

    public long getDownPayLoad() {
        return downPayLoad;
    }

    public void setDownPayLoad(long downPayLoad) {
        this.downPayLoad = downPayLoad;
    }

    public KpiWritable() {}

    public KpiWritable(String upPackNum, String downPackNum, String upPayLoad, String downPayLoad) {
        this.upPackNum = Long.parseLong(upPackNum);
        this.downPackNum = Long.parseLong(downPackNum);
        this.upPayLoad = Long.parseLong(upPayLoad);
        this.downPayLoad = Long.parseLong(downPayLoad);
    }

    public KpiWritable(long upPackNum, long downPackNum, long upPayLoad, long downPayLoad) {
        this.upPackNum = upPackNum;
        this.downPackNum = downPackNum;
        this.upPayLoad = upPayLoad;
        this.downPayLoad = downPayLoad;
    }

    @Override
    public void write(DataOutput out) throws IOException {

        out.writeLong(upPackNum);
        out.writeLong(downPackNum);
        out.writeLong(upPayLoad);
        out.writeLong(downPayLoad);
    }

    @Override
    public void readFields(DataInput in) throws IOException {

        upPackNum = in.readLong();
        downPackNum=in.readLong();
        upPayLoad = in.readLong();
        downPayLoad=in.readLong();
    }

    @Override
    public String toString() {
        String result = upPackNum + "\t" + downPackNum + "\t" + upPayLoad
                + "\t" + downPayLoad;
        return result;
    }
}
